package pl.edu.uj.tcs.blef.protocol;

import java.util.LinkedList;

import pl.edu.uj.tcs.blef.utils.Card;

public class NewHandRequestFactory implements RequestFactory {

	
	@Override
	@SuppressWarnings("unchecked")
	public Request build(Object[] parameters, RequestHandler handler) throws BuildFailedException {
		if(parameters.length != 2) throw new BuildFailedException("Two arguments expected.");
		try{
			int handSize = (Integer)parameters[0];
			LinkedList<Card> list = (LinkedList<Card>)parameters[1];
			StringBuilder sb = new StringBuilder();
			sb.append("NEW-HAND" + '\n');
			sb.append(handSize);
			for(Card c: list){
				sb.append('\n' + c.getCode() + " " + c.getColor().getCode());
			}
			
			return new NewHandRequest(sb.toString(), handler);
		} catch (ClassCastException e) { throw new BuildFailedException(e.getMessage()); }
	}

	@Override
	public Request parse(String message, RequestHandler handler) throws ParseFailedException, BuildFailedException {
		//TODO Add parser in the client
		return null;
	}

}
